<template>
    <el-dialog v-model="store.state.homeview.dialogFormVisible" title="请输入修改内容" @open="getInfo()" >
        <el-form :model="form" :label-width="formLabelWidth" :data=form>
            <el-form-item label="场地id" prop="placeid">
                <el-input v-model="form.placeid" autocomplete="off" />
            </el-form-item>
            
            <el-switch v-model="form.isFull" active-text="场地空闲" inactive-text="场地占用" style="margin-left: 70px"
                @change="Placer()" :key="form.isFull"/>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <!-- 绑定函数 -->
                <el-button @click="toggleDialog(0)">取消</el-button>
                <el-button type="primary" @click="toggleDialog(1)">确定</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script setup lang="ts">
import { ElMessage, ElMessageBox } from 'element-plus';
import {  reactive, } from 'vue'
import link from "@/util/api";
// 引用useStore
import { useStore } from 'vuex';

// 得到store对象
const store = useStore()
const formLabelWidth = '140px'
const form = reactive({
    s_name: '',
    s_id: '',
    s_type: '',
    isFull: true,
    placeid: '',
    p_price: '',
})
let toggleDialog = (num: Number) => {
    store.commit("SET_DIALOG");
    if (num == 0) {
        //   用户点击了取消
    } else {
        //   用户点击了确定
        //   得到输入框的值
        console.log(form.s_id + "---" + form.s_name);
    }
}

const getInfo: any = () => {
    form.placeid = store.state.homeview.rData
    form.isFull = store.state.homeview.sData
}

const Placer = async () => {
    form.isFull = !form.isFull
    await ElMessageBox.confirm(
        form.isFull ? '确定要把场地解封?' : '确定要把场地封禁',
        '注意!',
        {
            distinguishCancelAndClose: true,
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
    .then(() => {
      ElMessage({
        type: 'success',
        message: form.isFull ?  '成功解封' : '成功封禁' ,
      })
      //这里发送网络请求
      link(`/changePlaceStatus?placeid=${form.placeid}`, "get").then(ok => {
            console.log(ok)
            console.log(form.placeid);
            
        }) 
        form.isFull = !form.isFull
    })
}
</script>
<style scoped>
.el-button--text {
    margin-right: 15px;
}

.el-select {
    width: 300px;
}

/* .el-input {
  width: 300px;
} */
.dialog-footer button:first-child {
    margin-right: 10px;
}
</style>